load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/sql/colexecop:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "colexechash",
    srcs = [
        "hash.go",
        "hash_utils.go",
        "hashtable.go",
        ":gen-exec",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexechash",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/col/coldata",
        "//pkg/col/coldataext",  # keep
        "//pkg/col/typeconv",  # keep
        "//pkg/sql/colexec/colexecutils",
        "//pkg/sql/colexecerror",
        "//pkg/sql/colexecop",
        "//pkg/sql/colmem",
        "//pkg/sql/memsize",
        "//pkg/sql/sem/tree",  # keep
        "//pkg/sql/types",
        "//pkg/util/json",  # keep
        "//pkg/util/randutil",
        "@com_github_cockroachdb_apd_v3//:apd",  # keep
        "@com_github_cockroachdb_errors//:errors",
    ],
)

go_test(
    name = "colexechash_test",
    srcs = [
        "hash_test.go",
        "hash_utils_test.go",
        "main_test.go",
    ],
    embed = [":colexechash"],
    deps = [
        "//pkg/col/coldata",
        "//pkg/col/coldataext",
        "//pkg/settings/cluster",
        "//pkg/sql/colexec/colexecutils",
        "//pkg/sql/colmem",
        "//pkg/sql/execinfra",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/types",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/randutil",
    ],
)

# Map between target name and relevant template.
targets = [
    ("hash_utils.eg.go", "hash_utils_tmpl.go"),
    ("hashtable_distinct.eg.go", "hashtable_tmpl.go"),
    ("hashtable_full_default.eg.go", "hashtable_tmpl.go"),
    ("hashtable_full_deleting.eg.go", "hashtable_tmpl.go"),
]

# Define a file group for all the .eg.go targets.
eg_go_filegroup(
    name = "gen-exec",
    targets = targets,
)

# Define gen rules for individual eg.go files.
gen_eg_go_rules(targets)

disallowed_imports_test(
    "colexechash",
    [
        "//pkg/sql/colexec",
        "//pkg/sql/colexec/colexecagg",
        "//pkg/sql/colexec/colexecbase",
        "//pkg/sql/colexec/colexecjoin",
        "//pkg/sql/colexec/colexecproj",
        "//pkg/sql/colexec/colexecprojconst",
        "//pkg/sql/colexec/colexecsel",
        "//pkg/sql/colexec/colexecwindow",
        "//pkg/sql/execinfra",
    ],
)
